<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../static/layer/css/layui.css" media="all"/>
    <style>
        .tree{
            width:70%;
            margin-left: 100px;
            margin-top: 20px;
            overflow-y: auto;
        }
    </style>
</head>
<body>
<div class="tree">
    <ul id="hydropower"></ul>
</div>
<script type="text/javascript" src="../../../static/js/common/queryUtils.js"></script>
<script type="text/javascript" src="../../../static/layer/layui.js"></script>
<script>
    var $;
    var buildingId;
    var hydroType;
    layui.use(['jquery', 'layer', 'tree'], function () {
        $ = layui.jquery;
        buildingId = QueryUtils.GetQueryString("buildingId");//楼宇ID
        hydroType = QueryUtils.GetQueryString("hydroType");//楼宇ID
        getTree();
        //tree背景色修改
        $("body").on("mousedown",".layui-tree a cite",function(){
            $(".layui-tree a cite").css('color','black')
            $(this).css('color','red');
        })
    })
    function getTree() {
        $("#hydropower").empty();
        layui.tree({
            elem: '#hydropower' //传入元素选择器
            , nodes: getTreeNodes(hydroType, buildingId)
            , click: function (node) {
                parent.initParent(node.id,node.name);
                var i = parent.layer.getFrameIndex(window.name);
                parent.layer.close(i);
            }
        });
    }

    function getTreeNodes(type, buildingId) {
        var nodes;
        $.ajax({
            type: "post",
            url: "/hydropower/findbypid",
            async: false,
            data: {
                buildingId: buildingId,
                type: type
            },
            success: function (rs) {
                nodes = rs.data;
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
        return nodes;
    }
</script>
</body>
</html>